package com.qf.dao.impl;

import com.qf.dao.OrderDetailDao;
import com.qf.entity.OrderDetail;
import com.qf.util.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @Author AzureSky_X
 * @Date 2020/11/19 17:42
 * @Version 1.0
 */
public class OrderDetailDaoImpl implements OrderDetailDao {
    private QueryRunner qr=new QueryRunner();
    @Override
    public void insertOrderDetail(OrderDetail od) {

        String sql="insert into tb_orderdetail (oid,gid,num,sum) values (?,?,?,?)";
        try {
            qr.update(DbUtils.getConnection(), sql, od.getOid(), od.getGid(), od.getNum(), od.getSum());
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }

    @Override
    public List<OrderDetail> selectOrderDetailsByOid(Integer oid) {
        String sql="select * from tb_orderdetail where oid=?";
        List<OrderDetail> query = null;
        try {
            query = qr.query(DbUtils.getConnection(), sql, new BeanListHandler<>(OrderDetail.class), oid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return query;
    }
}
